﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using BCNPCObject.DB;


namespace BCNPCObject
{
    public class cls_STTIN_TRINHKY_Controller
    {
        #region   Atributes

        private DataSet ds = new DataSet();
        private DataTable dt = new DataTable();
        private STTIN_TRINHKY info;

        #endregion

        #region   Constructor

        public cls_STTIN_TRINHKY_Controller()
        {
            info = new STTIN_TRINHKY();
        }
        public cls_STTIN_TRINHKY_Controller(STTIN_TRINHKY Info)
        {
            this.info = Info;
        }

        #endregion

        #region   Properties

        public STTIN_TRINHKY pInfor
        {
            get { return info; }
            set { info = value; }
        }

        #endregion

        #region   Methods        

        public DataSet select_STTIN_TRINHKY(string strMadviqly, string TEN_BIEUBC)
        {
          
                try
                {
                    var q = from p in CMIS2.DB.STTIN_TRINHKY
                            where p.MA_DVIQLY == strMadviqly && p.TEN_BIEUBC == TEN_BIEUBC
                            select new
                            {
                                p.CHIEU_DAI,
                                p.CHIEU_RONG,
                                p.CO_CHU,
                                p.FONT_CHU,
                                p.KIEU_CHU,
                                p.MA_DVIQLY,
                                p.NGAY_CAPNHAT,
                                p.NOI_DUNG,
                                p.TEN_BIEUBC,
                                p.TEN_DOITUONG,
                                p.TOADO_DOC,
                                p.TOADO_NGANG,
                                p.FIELD_NAME,
                                p.FORMULA_NAME,
                            };
                    DataTable dt = CMISLibrary.Utility.LINQToDataTable(q);
                    dt.TableName = "STTIN_TRINHKY";
                    DataSet ds = new DataSet();
                    ds.Tables.Add(dt);
                    return ds;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            
        }

        public bool insert_STTIN_TRINHKY()
        {
            //long _ID = GetMaxSequenceByBranch();
            //if (_ID == -1) return false;
            try
            {
                CMIS2.DB.STTIN_TRINHKY.InsertOnSubmit(info);
                CMIS2.DB.SubmitChanges();
                CMIS2.ResetDB();
                return true;
            }
            catch (Exception ex)
            {
                CMIS2.ResetDB(); throw ex;
            }
        }
        public long GetMaxSequenceByBranch()
        {
            try
            {
                string strErr = "";
                long _ID = CMIS2.DB.ExecuteCommand("SELECT SEQ_STTIN_TRINHKY.NEXTVAL FROM dual", ref strErr);
                if (strErr == "") return _ID;
                else return -1;
            }
            catch
            {
                CMIS2.ResetDB(); return -1;
            }
        }      
        public bool update_STTIN_TRINHKY()
        {
            try
            {
                STTIN_TRINHKY objSTTIN_TRINHKY = CMIS2.DB.STTIN_TRINHKY.Single(c => c.MA_DVIQLY == info.MA_DVIQLY && c.TEN_BIEUBC == info.TEN_BIEUBC && c.FORMULA_NAME == info.FORMULA_NAME && c.FIELD_NAME == info.FIELD_NAME);
                objSTTIN_TRINHKY.CHIEU_DAI = info.CHIEU_DAI;
                objSTTIN_TRINHKY.CHIEU_RONG = info.CHIEU_RONG;
                objSTTIN_TRINHKY.CO_CHU = info.CO_CHU;
                objSTTIN_TRINHKY.FONT_CHU = info.FONT_CHU;
                objSTTIN_TRINHKY.KIEU_CHU = info.KIEU_CHU;
                objSTTIN_TRINHKY.NGAY_CAPNHAT = info.NGAY_CAPNHAT;
                objSTTIN_TRINHKY.NOI_DUNG = info.NOI_DUNG;
                objSTTIN_TRINHKY.TEN_DOITUONG = info.TEN_DOITUONG;
                objSTTIN_TRINHKY.TOADO_DOC = info.TOADO_DOC;
                objSTTIN_TRINHKY.TOADO_NGANG = info.TOADO_NGANG;
                CMIS2.DB.SubmitChanges();
                return true;
            }
            catch
            {
                CMIS2.ResetDB(); return false;
            }
        }      

        #endregion
    }
}
